package collection;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class GenericDemo {
    public static void main(String[] args) {
        Collection<String> c = new ArrayList<>();//泛型集合
        c.add("one");
        c.add("two");
        c.add("three");
        c.add("fore");
        c.add("five");
        //迭代器所指定的泛型应当与其遍历的集合的泛型一致
        Iterator<String> it = c.iterator();
        while (it.hasNext()) {//若有下一个元素
            String str = it.next();//获取下一个元素并强转为String类型
            System.out.println(str);
        }
        Collection<Point> c1 = new ArrayList<>();
        c1.add(new Point(1, 2));
        c1.add(new Point(3, 4));
        c1.add(new Point(5, 6));
        c1.add(new Point(7, 8));
        Iterator<Point> it1 = c1.iterator();
        while (it1.hasNext()) {
            Point p = it1.next();
            System.out.println(p);

        }
    }
}
